home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / ClipCmds.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  9.9 KB  |  351 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                ClipCmds.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef CLIPCMDS_H
  15. #include "ClipCmds.h"
  16. #endif
  17.  
  18. #ifndef DRAWCONT_H
  19. #include "DrawCont.h"
  20. #endif
  21.  
  22. #ifndef DRAWSEL_H
  23. #include "DrawSel.h"
  24. #endif
  25.  
  26. #ifndef BASESHP_H
  27. #include "BaseShp.h"
  28. #endif
  29.  
  30. #ifndef BOUNDSHP_H
  31. #include "BoundShp.h"
  32. #endif
  33.  
  34. #ifndef LINESHP_H
  35. #include "LineShp.h"
  36. #endif
  37.  
  38. #ifndef OVALSHP_H
  39. #include "OvalShp.h"
  40. #endif
  41.  
  42. #ifndef RECTSHP_H
  43. #include "RectShp.h"
  44. #endif
  45.  
  46. #ifndef RRECTSHP_H
  47. #include "RRectShp.h"
  48. #endif
  49.  
  50. #ifndef TEXTSHP_H
  51. #include "TextShp.h"
  52. #endif
  53.  
  54. #ifndef DRAWPART_H
  55. #include "DrawPart.h"
  56. #endif
  57.  
  58. #ifndef DRAWFRM_H
  59. #include "DrawFrm.h"
  60. #endif
  61.  
  62. #ifndef DRAWLINK_H
  63. #include "DrawLink.h"
  64. #endif
  65.  
  66. // ----- FrameWork Includes -----
  67.  
  68. #ifndef FWPRESEN_H
  69. #include "FWPresen.h"
  70. #endif
  71.  
  72. #ifndef FWSESION_H
  73. #include "FWSesion.h"
  74. #endif
  75.  
  76. // ----- OS Includes -----
  77.  
  78. #ifndef FWORDCOL_H
  79. #include "FWOrdCol.h"
  80. #endif
  81.  
  82. // ----- OpenDoc Includes -----
  83.  
  84. #ifndef SOM_Module_OpenDoc_Commands_defined
  85. #include <CmdDefs.xh>
  86. #endif
  87.  
  88. //========================================================================================
  89. // RunTime Info
  90. //========================================================================================
  91.  
  92. #ifdef FW_BUILD_MAC
  93. #pragma segment odfdrawcommand
  94. #endif
  95.  
  96. FW_DEFINE_AUTO(CDrawClipboardCommand)
  97.  
  98. //========================================================================================
  99. // CDrawClipboardCommand
  100. //========================================================================================
  101.  
  102. //----------------------------------------------------------------------------------------
  103. //    CDrawClipboardCommand constructor
  104. //----------------------------------------------------------------------------------------
  105.  
  106. CDrawClipboardCommand::CDrawClipboardCommand(Environment* ev, 
  107.                                             ODCommandID commandID,
  108.                                             CDrawPart* part, 
  109.                                             CDrawFrame* frame, 
  110.                                             CDrawSelection* selection,
  111.                                             FW_Boolean canUndo) :
  112.     FW_CClipboardCommand(ev, commandID, frame, canUndo),
  113.         fDrawPart(part),
  114.         fDrawSelection(selection),
  115.         fUndoContent(NULL),
  116.         fSavedLink(NULL),
  117.         fLinkSources(NULL)
  118. {
  119.     FW_END_CONSTRUCTOR
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    CDrawClipboardCommand destructor
  124. //----------------------------------------------------------------------------------------
  125.  
  126. CDrawClipboardCommand::~CDrawClipboardCommand()
  127. {
  128.     FW_START_DESTRUCTOR
  129.     delete fUndoContent;
  130.     delete fLinkSources;
  131. }
  132.  
  133. //----------------------------------------------------------------------------------------
  134. //    CDrawClipboardCommand::SaveUndoState
  135. //----------------------------------------------------------------------------------------
  136. void CDrawClipboardCommand::SaveUndoState(Environment* ev)    // Override
  137. {
  138.     ODCommandID commandID = GetCommandID(ev);
  139.     
  140.     if (commandID == kODCommandCut || commandID == kODCommandClear)
  141.     {
  142.         FW_ASSERT(fUndoContent == NULL);
  143.         fUndoContent = FW_NEW(CDrawUndoContent, (ev, fDrawPart, fDrawSelection));
  144.         
  145.         // Obtain a list of links sources to update before removing anything!
  146.         // This will do for now, but doesn't filter out any sources
  147.         // which will be removed in their entirety, so needn't be updated.
  148.         
  149.         fLinkSources = fDrawSelection->GetSelectedLinkSources();
  150.         
  151.     }
  152. }
  153.  
  154. //----------------------------------------------------------------------------------------
  155. //    CDrawClipboardCommand::SaveRedoState
  156. //----------------------------------------------------------------------------------------
  157. void CDrawClipboardCommand::SaveRedoState(Environment* ev)    // Override
  158. {
  159.     if (this->IsPasteWithoutLink(ev))
  160.     {
  161.         FW_ASSERT(fUndoContent == NULL);
  162.         fUndoContent = FW_NEW(CDrawUndoContent, (ev, fDrawPart, fDrawSelection));
  163.     }    
  164. }
  165.  
  166. //----------------------------------------------------------------------------------------
  167. //    CDrawClipboardCommand::FreeUndoState
  168. //----------------------------------------------------------------------------------------
  169. void CDrawClipboardCommand::FreeUndoState(Environment* ev)    // Override
  170. {
  171.     ODCommandID commandID = GetCommandID(ev);
  172.     
  173.     if (commandID == kODCommandCut || commandID == kODCommandClear)
  174.     {
  175.         // Delete link sources left empty because all their shapes were removed
  176.         fUndoContent->DeleteEmptyLinkSources(ev);
  177.  
  178.         // Delete undo data
  179.         fUndoContent->DeleteSavedShapesAndLinks(ev);
  180.     }
  181. }
  182.  
  183. //----------------------------------------------------------------------------------------
  184. //    CDrawClipboardCommand::FreeRedoState
  185. //----------------------------------------------------------------------------------------
  186. void CDrawClipboardCommand::FreeRedoState(Environment* ev)    // Override
  187. {
  188.     if (this->IsPasteWithoutLink(ev))
  189.         fUndoContent->DeleteSavedShapes(ev);
  190. }
  191.  
  192. //----------------------------------------------------------------------------------------
  193. //    CDrawClipboardCommand::UndoIt
  194. //----------------------------------------------------------------------------------------
  195. void CDrawClipboardCommand::UndoIt(Environment* ev)    // Override
  196. {
  197.     FW_CClipboardCommand::UndoIt(ev);    // call inherited
  198.  
  199.     switch (GetCommandID(ev))
  200.     {
  201.         case kODCommandCut:
  202.         case kODCommandClear:
  203.             fUndoContent->RestoreShapeSelection(ev);
  204.             fUndoContent->RestoreLinks(ev);
  205.             break;
  206.  
  207.         case kODCommandPasteAs:
  208.             if (fSavedLink)
  209.             {
  210.                 fSavedLink->SelectShapes(ev);    // set the selection's update shape
  211.                 GetDrawLinkManager(ev)->UndoPasteAs(ev, fSavedLink);
  212.                 GetPresentation(ev)->Invalidate(ev, fDrawSelection->GetUpdateShape());
  213.                 break;
  214.             }    
  215.         //    else fall through to kODCommandPaste
  216.  
  217.         case kODCommandPaste:
  218.             fUndoContent->RemoveShapeSelection(ev);
  219.             break;
  220.     }    
  221. }
  222.  
  223. //----------------------------------------------------------------------------------------
  224. //    CDrawClipboardCommand::RedoIt
  225. //----------------------------------------------------------------------------------------
  226. void CDrawClipboardCommand::RedoIt(Environment* ev)    // Override
  227. {
  228.     FW_CClipboardCommand::RedoIt(ev);    // call inherited
  229.  
  230.     switch (GetCommandID(ev))
  231.     {
  232.         case kODCommandCut:
  233.         case kODCommandClear:
  234.             fUndoContent->RemoveShapeSelection(ev);
  235.             fUndoContent->RemoveFromLinks(ev);
  236.             break;
  237.  
  238.         case kODCommandPasteAs:
  239.             if (fSavedLink)
  240.             {
  241.                 GetDrawLinkManager(ev)->RedoPasteAs(ev, fSavedLink);
  242.                 GetPresentation(ev)->Invalidate(ev, fDrawSelection->GetUpdateShape());
  243.                 break;
  244.             }    
  245.         //    else fall through to kODCommandPaste
  246.  
  247.         case kODCommandPaste:
  248.             fUndoContent->RestoreShapeSelection(ev);
  249.             break;
  250.     }    
  251. }
  252.  
  253. //----------------------------------------------------------------------------------------
  254. //    CDrawClipboardCommand::PreCommand
  255. //----------------------------------------------------------------------------------------
  256.  
  257. void CDrawClipboardCommand::PreCommand(Environment* ev)
  258. {
  259.     ODCommandID commandID = GetCommandID(ev);
  260.     
  261.     if (commandID == kODCommandPaste || commandID == kODCommandPasteAs)
  262.         fDrawSelection->CloseSelection(ev);
  263. }
  264.  
  265. //----------------------------------------------------------------------------------------
  266. //    CDrawClipboardCommand::CommandDone
  267. //----------------------------------------------------------------------------------------
  268.  
  269. void CDrawClipboardCommand::CommandDone(Environment* ev)
  270. {
  271.     ODCommandID commandID = GetCommandID(ev);
  272.  
  273.     if (commandID == kODCommandPaste)
  274.         fDrawSelection->CenterSelection(ev, GetFrame(ev));
  275.     else if (commandID == kODCommandPasteAs)
  276.     {
  277.         fSavedLink = (CDrawSubscribeLink*)GetNewLink(ev);
  278.         if (fSavedLink && fSavedLink->IsEstablished(ev))    // cross-doc link not yet established
  279.         {
  280.             // Select the newly-subscribed shapes
  281.             fSavedLink->SelectShapes(ev);
  282.         
  283.             // Offset the selection, saving the offset for later updates
  284.             FW_CPoint offset = fDrawSelection->CenterSelection(ev, GetFrame(ev));
  285.         
  286.             // Save information about newly-created link
  287.             fSavedLink->SetUpdateOffset(ev, offset);
  288.         }
  289.     }
  290.     else if (commandID == kODCommandCut || commandID == kODCommandClear)
  291.     {
  292.         fUndoContent->RemoveFromLinks(ev);
  293.     }
  294. }
  295.  
  296. //----------------------------------------------------------------------------------------
  297. //    CDrawClipboardCommand::IsPasteWithoutLink
  298. //----------------------------------------------------------------------------------------
  299.  
  300. FW_Boolean CDrawClipboardCommand::IsPasteWithoutLink(Environment* ev) const
  301. {
  302.     if (GetCommandID(ev) == kODCommandPaste)
  303.         return TRUE;
  304.     if (GetCommandID(ev) == kODCommandPasteAs)
  305.         return (fSavedLink == NULL);
  306.         
  307.     return FALSE;
  308. }
  309.  
  310. //----------------------------------------------------------------------------------------
  311. //    CDrawClipboardCommand::GetDrawLinkManager
  312. //----------------------------------------------------------------------------------------
  313.  
  314. CDrawLinkManager* CDrawClipboardCommand::GetDrawLinkManager(Environment* ev) const
  315. {
  316.     return (CDrawLinkManager*)GetPart(ev)->GetLinkManager(ev);
  317. }
  318.  
  319. //----------------------------------------------------------------------------------------
  320. //    CDrawClipboardCommand::CommitUndone
  321. //----------------------------------------------------------------------------------------
  322.  
  323.  
  324.  
  325. //----------------------------------------------------------------------------------------
  326. //    CDrawClipboardCommand::CommitDone
  327. //----------------------------------------------------------------------------------------
  328.  
  329.  
  330. //----------------------------------------------------------------------------------------
  331. //    CDrawClipboardCommand::PropagateChanges
  332. //----------------------------------------------------------------------------------------
  333. void CDrawClipboardCommand::PropagateChanges(Environment* ev,  ODUpdateID id )
  334. {
  335.     if (fLinkSources)
  336.     {
  337.         //--- Update affected links ---
  338.         id = FW_CSession::UniqueUpdateID(ev);
  339.         CDrawPublishLinkCollectionIterator iter(fLinkSources);
  340.         for (CDrawPublishLink* link = iter.First(); iter.IsNotComplete(); link = iter.Next())
  341.         {
  342.             link->ContentUpdated(ev, id);
  343.         }
  344.     }
  345.     
  346.     FW_CClipboardCommand::PropagateChanges(ev, id);
  347. }
  348.  
  349.  
  350.  
  351.